<template>
  <div class="container">
    <div>
      <el-row :gutter="24">
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item>
              <!-- <el-radio v-model="form.radioData" label="日">按日期：</el-radio> -->
              <span>查询日期：</span>
              <el-date-picker
                v-model="form.valueDay"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
              ></el-date-picker>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="道路名称：">
              <el-input
                v-model="form.roadName"
                placeholder="请输入道路名称"
                clearable
                style="width: 200px"
              ></el-input>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="分组：">
              <el-select
                v-model="CLIENT_GROUP_NAME"
                placeholder="请选择分组"
                @change="groupchange"
              >
                <el-option
                  v-for="(item, index) in groupingList"
                  :value="item.CLIENT_GROUP_NO"
                  :label="item.CLIENT_GROUP_NAME"
                  :key="index"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form" style="float: left">
            <el-button size="mini" type="primary" @click="getlistdata"
              >查 询</el-button
            >
            <el-button size="mini" type="success" @click="exportExcel"
              >导 出</el-button
            >
          </el-form>
        </el-col>
      </el-row>
      <el-row :gutter="0" style="margin-top: 20px; margin-bottom: 20px">
        <el-col :span="3" :offset="4">
          <span>{{ formInfo.all }}</span>
        </el-col>
        <el-col :span="3">
          <span>{{ formInfo.work }}</span>
        </el-col>
        <el-col :span="3">
          <span>{{ formInfo.one }}</span>
        </el-col>
        <el-col :span="3">
          <span>{{ formInfo.two }}</span>
        </el-col>
        <el-col :span="3">
          <span>{{ formInfo.three }}</span>
        </el-col>
      </el-row>
    </div>
    <el-table
      border
      :data="
        tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)
      "
      highlight-current-row
    >
      <el-table-column
        prop="ROADNAME2"
        label="道路名称"
        align="center"
        width="150"
      ></el-table-column>
      <el-table-column
        prop="REMARKS2"
        label="作业公司"
        align="center"
        width="100"
      ></el-table-column>
      <el-table-column
        prop="LRoadist"
        label="道路长度（米）"
        align="center"
      ></el-table-column>

      <el-table-column prop="ZL" label="正向作业长度（米）"></el-table-column>
      <el-table-column prop="ZLBFB" label="百分比"></el-table-column>
      <el-table-column prop="FL" label="反向作业长度（米）"></el-table-column>
      <el-table-column prop="FLBFB" label="百分比"></el-table-column>
      <el-table-column
        prop="NOWORKZHENG"
        label="正向各种类型车辆均未作业长度（米）"
        width="150"
      ></el-table-column>
      <el-table-column prop="NOWORKZHENGBFB" label="百分比"></el-table-column>
      <el-table-column
        prop="NOWORKFAN"
        label="反向各种类型车辆均未作业长度（米）"
        width="150"
      ></el-table-column>
      <el-table-column prop="NOWORKFANBFB" label="百分比"></el-table-column>
      <el-table-column prop="ZC" label="正向作业次数"></el-table-column>
      <el-table-column prop="FC" label="反向作业次数"></el-table-column>
      <el-table-column
        prop="LWORK"
        label="累计作业长度（米）"
      ></el-table-column>
      <el-table-column prop="LWORKBFB" label="百分比"></el-table-column>
      <el-table-column
        prop="JSLWORK"
        label="机扫车作业长度（米）"
      ></el-table-column>
      <el-table-column prop="JSLWORKBFB" label="百分比"></el-table-column>
      <el-table-column
        prop="QXLWORK"
        label="高压清洗车作业长度（米）"
      ></el-table-column>
      <el-table-column prop="QXLWORKBFB" label="百分比"></el-table-column>
      <el-table-column
        prop="SSLWORK"
        label="洒水车作业长度（米）"
      ></el-table-column>
      <el-table-column prop="SSLWORKBFB" label="百分比"></el-table-column>
      <el-table-column
        prop="XLLWORK"
        label="洗路车作业长度（米）"
      ></el-table-column>
      <el-table-column prop="XLLWORKBFB" label="百分比"></el-table-column>
      <el-table-column
        prop="JSNoWorkRoadLength"
        label="机扫车未作业长度（米）"
      ></el-table-column>
      <el-table-column
        prop="JSNoWorkRoadLengthBFB"
        label="百分比"
      ></el-table-column>
      <el-table-column
        prop="GYNoWorkRoadLength"
        label="高压清洗车未作业长度（米）"
      ></el-table-column>
      <el-table-column
        prop="GYNoWorkRoadLengthBFB"
        label="百分比"
      ></el-table-column>
      <el-table-column
        prop="SSNoWorkRoadLength"
        label="洒水车未作业长度（米）"
      ></el-table-column>
      <el-table-column
        prop="SSNoWorkRoadLengthBFB"
        label="百分比"
      ></el-table-column>
      <el-table-column
        prop="XLNoWorkRoadLength"
        label="洗路车未作业长度（米）"
      ></el-table-column>
      <el-table-column
        prop="XLNoWorkRoadLengthBFB"
        label="百分比"
      ></el-table-column>
      <!-- <el-table-column label="操作" width="100">
        <template slot-scope="scope">
          <el-button type="text" icon="el-icon-info" @click="handleEdit(scope.$index, scope.row)">详情</el-button>
        </template>
      </el-table-column> -->
    </el-table>
    <div class="pagination">
      <el-pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :current-page="currentPage"
        :page-size="pageSize"
        :total="tableData.length"
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import "@/assets/css/common.css";
import { formatDate } from "@/common/js/date.js";
import export2Excel from "@/utils/exportExcel/index.js";
export default {
  data() {
    return {
      currentPage: 1, //初始页
      pageSize: 10, //    每页的数据
      formInfo: {
        all: "",
        work: "",
        one: "",
        two: "",
        three: "",
      },
      form: {
        roadName: "",
        radioData: "日",
        valueDay: formatDate(
          new Date(new Date() - 3600 * 1000 * 24),
          "yyyy-MM-dd"
        ),
        valueMonth: "",
      },
      tableData: [],
      originalData: [],
      exportExcelData: [],
      groupingList: [],
      CLIENT_GROUP_NAME: "",
    };
  },
  created() {
    this.getGroupingList();
  },
  methods: {
    // 获得分组列表
    async getGroupingList() {
      var url =
        "Vehicle/GetClientInfo?client_no=" + localStorage.getItem("CLIENT_NO"); // zxdata
      let { data } = await this.$Http.get(url);
      this.groupingList = data;
      // this.groupingList.unshift({ "CLIENT_GROUP_NO": localStorage.getItem("CLIENT_NO"), "CLIENT_GROUP_NAME": "全部" })
      this.CLIENT_GROUP_NAME = data[0].CLIENT_GROUP_NO;
      // this.getRoadList(data[0].CLIENT_GROUP_NO);
      this.getlistdata();
    },
    async getlistdata() {
      this.currentPage = 1;
      var date = "";
      if (this.form.radioData === "日") {
        date = this.form.valueDay;
      }
      if (this.form.radioData === "月") {
        date = this.form.valueMonth;
      }
      var url =
        "Vehicle/GetExcelCar2?clientName=" +
        this.CLIENT_GROUP_NAME +
        "&date=" +
        date;
      const { data } = await this.$Http.get(url);
      this.exportExcelData = data;

      this.formInfo.one = "主干：0条";
      this.formInfo.two = "次干：0条";
      this.formInfo.three = "支路：0条";

      for (var i = 0; i < data.length; ) {
        var title = data[i].TITLE;
        if (title.includes("总计")) {
          this.formInfo.all = title;
        }
        if (title.includes("已作业道路")) {
          this.formInfo.work = title;
        }
        if (title.includes("主干")) {
          this.formInfo.one = title;
        }
        if (title.includes("次干")) {
          this.formInfo.two = title;
        }
        if (title.includes("支路")) {
          this.formInfo.three = title;
        }
        if (data[i].ROADNAME2 === "道路名称" || data[i].ROADNAME2 === "") {
          data.splice(i, 1);
        } else {
          i++; //只有在没有删除元素时才对索引 i++
        }
      }
      this.tableData = data;
      if (this.form.roadName != "")
        this.tableData = this.tableData.filter((item) =>
          item.ROADNAME2.includes(this.form.roadName)
        );
    },
    // 导出Excel
    exportExcel() {
      let excelName = "道路作业统计表";
      const tHeader = [
        "道路名称",
        "作业公司",
        "道路长度（米）",
        "累计作业长度（米）",
        "百分比",
        "机扫车作业长度（米）",
        "百分比",
        "高压清洗车作业长度（米）",
        "百分比",
        "洒水车作业长度（米）",
        "百分比",
        "洗路车作业长度（米）",
        "百分比",
        "正向作业长度（米）",
        "百分比",
        "反向作业长度（米）",
        "百分比",
        "正向作业次数",
        "反向作业次数",
        "正向各种类型车辆均未作业长度（米）",
        "百分比",
        "反向各种类型车辆均未作业长度（米）",
        "百分比",
        "机扫车未作业长度（米）",
        "百分比",
        "高压清洗车未作业长度（米）",
        "百分比",
        "洒水车未作业长度（米）",
        "百分比",
        "洗路车未作业长度（米）",
        "百分比",
      ];
      const filterVal = [
        "ROADNAME2",
        "REMARKS2",
        "LRoadist",
        "LWORK",
        "LWORKBFB",
        "JSLWORK",
        "JSLWORKBFB",
        "QXLWORK",
        "QXLWORKBFB",
        "SSLWORK",
        "SSLWORKBFB",
        "XLLWORK",
        "XLLWORKBFB",
        "ZL",
        "ZLBFB",
        "FL",
        "FLBFB",
        "ZC",
        "FC",
        "NOWORKZHENG",
        "NOWORKZHENGBFB",
        "NOWORKFAN",
        "NOWORKFANBFB",
        "JSNoWorkRoadLength",
        "JSNoWorkRoadLengthBFB",
        "GYNoWorkRoadLength",
        "GYNoWorkRoadLengthBFB",
        "SSNoWorkRoadLength",
        "SSNoWorkRoadLengthBFB",
        "XLNoWorkRoadLength",
        "XLNoWorkRoadLengthBFB",
      ];
      export2Excel(tHeader, filterVal, this.exportExcelData, excelName);
    },
    //详情
    handleEdit(index, row) {
      //   this.idx = index;
      //   this.form = row;
      //   this.editVisible = true;
    },
    // 分页导航
    handlePageChange(currentPage) {
      this.currentPage = currentPage;
      // console.log(this.currentPage)
      // this.$set(this.query, 'pageIndex', val);
      // this.getData();
    },
    handleSizeChange(size) {
      this.pageSize = size;
      console.log(this.pageSize);
    },
  },
};
</script>
<style>
.content {
  overflow-y: scroll;
}
.el-col-6 {
  min-width: 400px;
  min-height: 50px;
}
.el-table th {
  height: 40px;
}
</style>